﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using ExtAspNet;
using Ylh.BLL;
using System.Data;

public partial class Module_CustServerManger_CustServerManger : PageBase 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LoadTv();
        }
    }

    private void LoadTv()
    {
        Ylh.BLL.DepartmentBLL debll = new DepartmentBLL(DbConnectionStr);

        DataTable dt = debll.GetServerDepartMentInfo(-1, true);

        ExtAspNet.TreeNode Tn = new ExtAspNet.TreeNode();
        Tn.Text = "未分配";
        Tn.NodeID = "-1";
        Tn.NavigateUrl = "CustServerList.aspx?StaffID=-1";
        Tn.Target = "CustServer";
        Tn.Leaf = true;
        Tree1.Nodes.Add(Tn);

        ExtAspNet.TreeNode tn = new ExtAspNet.TreeNode();
        foreach (DataRow dr in dt.Rows)
        {
            tn.NodeID = dr["DepartmentID"].ToString();
            tn.Text = dr["DepartmentName"].ToString();

            tn.Leaf = false;
            
            Tree1.Nodes.Add(tn);
        }
    }
    protected void Tree1_NodeExpand(object sender, TreeExpandEventArgs e)
    {
        LoadServerStaff(e.Node);
    }

    private void LoadServerStaff(ExtAspNet.TreeNode treeNode)
    {
        Ylh.BLL.StaffBLL blls = new StaffBLL(DbConnectionStr);

       DataTable dt= blls.GetStaffData(treeNode.NodeID);

       ExtAspNet.TreeNode tn;
       foreach (DataRow dr in dt.Rows)
       {
           if ( Convert.ToDecimal(dr["StaffID"])==base.StaffID)
           {
               continue;
           }

          tn = new ExtAspNet.TreeNode();
          tn.NodeID=dr["StaffID"].ToString();
          tn.Text = dr["StaffName"].ToString();

          tn.NavigateUrl = "~/Module/CustServerManger/CustServerList.aspx?StaffID=" + dr["StaffID"].ToString();

          tn.Target = "CustServer";

          tn.Leaf = true;

          treeNode.Nodes.Add(tn);
       }

    }
}